package pers.xiaojun.boot.common.config.properties;

import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;

/**
 * 验证码配置
 *
 * @author xiaojun
 * @since 2025-10-06
 */
@Data
@ConfigurationProperties(prefix = "xiaojun.captcha")
@Validated
public class CaptchaProperties {

    /**
     * 验证码类型
     * {@link Type}
     */
    @NotNull(message = "验证码类型不能为空")
    private Type type = Type.RANDOM;

    /**
     * 干扰类型
     * {@link DisturbType}
     */
    @NotNull(message = "验证码干扰类型不能为空")
    private DisturbType disturbType = DisturbType.LINE;

    /**
     * 干扰数量
     */
    @Min(value = 0, message = "干扰数量数范围：0-20")
    @Max(value = 20, message = "干扰数量数范围：0-20")
    private Integer disturbCount = 10;

    /**
     * 验证码图片宽度
     */
    @NotNull
    @Min(value = 1, message = "验证码图片宽度范围：1-360")
    @Max(value = 360, message = "验证码图片宽度范围：1-360")
    private Integer width = 120;

    /**
     * 验证码图片高度
     */
    @Min(value = 1, message = "验证码图片高度范围：1-360")
    @Max(value = 360, message = "验证码图片高度范围：1-360")
    private Integer height = 40;

    /**
     * 随机字符验证码字符池（默认英文+数字）
     */
    private String baseChar;

    /**
     * 随机字符验证码字符数
     */
    @Min(value = 4, message = "验证码字符数范围：4-8")
    @Max(value = 8, message = "验证码字符数范围：4-8")
    private Integer codeCount = 4;

    /**
     * 算术验证码位数
     */
    @Min(value = 1, message = "算术验证码位数应为1-4位")
    @Max(value = 4, message = "算术验证码位数应为1-4位")
    private Integer numberLength = 2;

    /**
     * 验证码存活时间（单位：秒，默认300）
     */
    private Integer expiresIn = 300;


    @Getter
    @AllArgsConstructor
    public enum DisturbType {

        LINE("线段干扰"),
        CIRCLE("圆圈干扰"),
        SHEAR("扭曲干扰");

        private final String description;
    }

    @Getter
    @AllArgsConstructor
    public enum Type {
        MATH("算术验证码"),
        RANDOM("随机字符验证码");

        private final String description;
    }
}
